package wangchao.validate;

import ch.qos.logback.core.joran.spi.JoranException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import wangchao.conf.FormatUtil;
import wangchao.conf.LogBackConfigLoader;
import wangchao.validate.filter.DataValidate;
import wangchao.validate.filter.DataValidateFilter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * 验证测试
 * Created by ashin on 2018/11/1.
 */
public class ValidateTest {

    static {
        try {
            LogBackConfigLoader.load("src/main/config/logback.xml");
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JoranException e) {
            e.printStackTrace();
         }
    }

    protected static final Logger logger = LoggerFactory.getLogger(ValidateTest.class);


    public static void main(String[] args) throws NoSuchMethodException {

        Map map = new HashMap();
        map.put("userName", "baike.xsoftlab.net");
        map.put("passWord", "1111111111111");
        Method method = LoginValidate.class.getDeclaredMethod("doLogin", Map.class);
        DataValidateFilter dataValidate = new DataValidate();
        JSONObject jsonObject = dataValidate.invokeMethodValidate(method, (JSONObject) JSON.toJSON(map));
//        JSONObject jsonObject = dataValidate.invokeFieldValidate(method.getParameters()[0],"userName","zhangsan");
        FormatUtil.printJson(jsonObject.toJSONString());
    }
}
